package com.markyao.recos;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.atomic.AtomicInteger;

@Configuration
public class RaftBeanMapsConfig {

    /**
     * 来自领导人的心跳
     * @return
     */
    @Bean("raftHearBeat")
    public AtomicInteger raftHearBeat(){
        return new AtomicInteger(0);//初始情况下为0 没有心跳,如果有心跳则为1
    }
    /**
     * 是否处于竞选周期
     * @return
     */
    @Bean("isElection")
    public AtomicInteger isElection(){
        return new AtomicInteger(0);
    }


    @Bean(name = "leaderMetadata")
    public ConcurrentHashMap<String,Object> leaderMetadata(){
        ConcurrentHashMap<String, Object> leaderMap = new ConcurrentHashMap<>();
        leaderMap.put("alive",false);
        return leaderMap;
    }
}
